package heip.generator.generer;

import heip.generator.entity.TableClazz;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;


/**
 * 生成service类
 * @author HSWHM
 *
 */
public class ServiceDaoGenerator extends AbstractGenerator{
	/**
	 *需要手动修改的变量 
	 */
	//模块名
	private String moduleName = null;
	
	public  ServiceDaoGenerator(String moduleName){
		this.moduleName = moduleName;
		gg.put("moduleName",this.moduleName);
		gg.put("now", new Date());
	}
	
	public void generatorEmpty(TableClazz tableClass,String modelType) throws Exception{
		//1.选择相应的模板
		//"基本","树","审核"
	/*	String daoTem= null;
		String serviceTem = null;
		if("树".equals(modelType)){daoTem = treeTem;}
		else if("审核".equals(modelType)){temName = auditTem;}
		else{temName= baseTem;}
		String templatePath = getRealTemPath(temName);
		
	*/	
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("model", tableClass);
		generator.generateByMap(map, getRealTemPath(emptyDao));
		generator.generateByMap(map, getRealTemPath(emptyService));
	}
	
	public void generator(TableClazz tableClazz,Map<String,Object> params)throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("model", tableClazz);
		map.putAll(params);
		
		generator.generateByMap(map, getRealTemPath(baseDao));
		generator.generateByMap(map, getRealTemPath(baseService));
		//只需要生成子表的dao
		for(TableClazz subClass:tableClazz.getSubClazzes()){
			map.put("model",subClass);
			generator.generateByMap(map, getRealTemPath(baseDao));
		}
		
	}
	
		
	private String baseDao = "TEMPLATE_1.0/dao/base";
	private String emptyDao = "TEMPLATE_1.0/service/empty";
	//private String treeDao = "TEMPLATE_1.0/dao/base";
	//private String baseDao = "TEMPLATE_1.0/dao/base";
	
	private String baseService ="TEMPLATE_1.0/service/base";
	private String emptyService = "TEMPLATE_1.0/service/empty";
	/*private String baseDao = "TEMPLATE_1.0/dao/base";
	private String baseDao = "TEMPLATE_1.0/dao/base";*/
	
}